package horde

import "event-chain/core/common"

type IFilter[T any] interface {
	common.IOnce
	Handle(int, T) bool
}

type Filter[T any] struct {
	common.One
	handle func(int, T) bool
}

func NewFilter[T any](handle func(int, T) bool, isOnce bool) *Filter[T] {
	res := &Filter[T]{handle: handle}
	res.SetOnce(isOnce)
	return res
}

func (f *Filter[T]) Handle(i int, data T) bool {
	return f.handle(i, data)
}
